/* eslint-disable */
// self.addEventListener('message', e => {
//   // get action method
//   if (!e.data.action) return

//   if (e.data.action === 'start') {
//     self.postMessage('message')
//   }
// })

const maxSegmentSize = 500000
const positionStride = 12

import { mockBigData } from '../views/MainBoard/Chart/mock'

// const largeMessage = JSON.stringify(mockBigData(1024 * 1024 * 100))
const buffer = new ArrayBuffer(maxSegmentSize * 4 * positionStride)
const largeMessage = new Float32Array(buffer)

// const buffer2 = new SharedArrayBuffer(maxSegmentSize * 6 * positionStride)
// const largeMessage2 = new Float32Array(buffer2)

console.log(
  'maxSegmentSize * 4 * positionStride>>>>>>',
  (maxSegmentSize * 4 * positionStride) / 1024 / 1024
)

// largeMessage2[0] = 1

function run(callback) {
  let animateId = null
  let preTimestamp = 0

  function animate(timestamp) {
    animateId = requestAnimationFrame(animate)

    if (preTimestamp) {
      callback(timestamp - preTimestamp)
    }

    preTimestamp = timestamp
  }

  animate()

  return () => {
    cancelAnimationFrame(animateId)
  }
}

run(() => {
  const p = largeMessage.slice(0, largeMessage.length)
  self.postMessage({
    largeMessage: p,
  }, [p.buffer])
})
